package cn.ante.ymcc.mq.producer;

import cn.ante.ymcc.dto.MessagePushDto;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
@Component
public class CourseProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public Boolean sendSmsMeassage(MessagePushDto message){

        Message<MessagePushDto> messagePushDtoMessage = MessageBuilder.withPayload(message).build();
        SendResult sendResult = rocketMQTemplate.syncSend("topic-course:tags-smscourse", messagePushDtoMessage);
        SendStatus sendStatus = sendResult.getSendStatus();
        if (sendStatus == SendStatus.SEND_OK){
            return true;
        }
        return false;
    }
}
